<template>
	<view class="container">
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption" :top="230">
			<view v-for="(item,index) in list " :key="index">
				<listTemplate :itemDetail="item" :listType="listType" @Acceptance="Acceptance"/>
			</view>
		</mescroll-uni>
	</view>
</template>
 
<script>
	import listTemplate from '../listTemplate/index.vue';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";	
	import { repairManageList, repairManageSettlement } from '@/api/bookingManagement.js';
	export default {
		components:{
			listTemplate
		},
		props:{
			listType:{type:Number,default:0},
			repairTime:{type:Number,default:0},//送修时间时间戳
		},
		mixins: [MescrollMixin],
		data(){
			return {
				list:[],
				pageIndexNum:1,
				pageSizeNum:10,
				upOption:{
					auto:false
				},
			}
		},
		watch:{
			// 状态值改变刷新页面数据
			listType(newVal){
				this.list=[]
				let page={num:this.pageIndexNum,size:this.pageSizeNum}
				this.upCallback(page)
			},
			//送修日期改变刷新页面数据
			repairTime(newVal){
				this.list=[]
				let page={num:this.pageIndexNum,size:this.pageSizeNum}
				this.upCallback(page)
			}
		},
		methods:{
			downCallback(){
				this.list = []
				this.mescroll.resetUpScroll( true )				
			},
			// 维修列表内容
			async upCallback(page){
				this.pageIndexNum=page.num
				this.pageSizeNum=page.size
				let params = {
					pageIndex:page.num,
					pageSize:page.size,
					status:Number(this.listType)+1,//状态
					repairTime:this.repairTime,//送修时间时间戳
				}
				let res = await repairManageList(params)
				if(res.result === '1'){
					this.mescroll.endSuccess(res.rows.length)//下拉刷新
					this.list = [...this.list,...res.rows]
				} else { 
					this.mescroll.endErr()//上拉加载
				}
				this.mescroll.endSuccess(1)//下拉刷新
			},
			// 申请结算(跳转页面未完成)
			Acceptance(val){
				let params = {repairOrderId:val.repairOrderId}
				let res = repairManageSettlement(params)
				if(res.result === '1'){
					this.mescroll.endSuccess(res.rows.length)//下拉刷新
				}else { 
					this.mescroll.endErr()//上拉加载
				}
				this.mescroll.endSuccess(1)//下拉刷新
			}
		}
	}
	
</script>
<style lang="scss" scoped>
	
</style>